﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Gencode.Common.SQL;

namespace Gencode.PrsCommon.App
{
	public class Option
	{
		static public double NumberValue(string typ, int wert)
		{
			DataView dv = SimpleQuerry.ExecuteForDataView("select zahlwert from Options where typ = '" + typ + "' and wert = " + wert);
			if (dv.Count > 0)
			{
				return Convert.ToDouble(dv[0].Row[0].ToString());
			}
			return 0;
		}

		static public string StringValue(string typ, int wert)
		{
			DataView dv = SimpleQuerry.ExecuteForDataView("select textwert from Options where typ = '" + typ + "' and wert = " + wert);
			if (dv.Count > 0)
			{
				return dv[0].Row[0].ToString();
			}
			return "";
		}

		/// <summary>
		/// Gets the amount of options asociated with the type
		/// </summary>
		/// <param name="typ"></param>
		/// <returns></returns>
		static public int OptionsCount(string typ)
		{
			int retVal = 0;
			DataView dv = SimpleQuerry.ExecuteForDataView("select count(typ) from Options where typ = '" + typ + "'");
			if (dv.Count > 0)
			{
				try
				{
					retVal = int.Parse(dv[0].Row[0].ToString());
				}
				catch { }
			}
			return retVal;
		}
	}
}
